package net.maku.im.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.im.dto.ImPrivateMessageQueryDTO;
import net.maku.im.service.ImPrivateMessageService;
import net.maku.im.vo.ImPrivateMessageVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 私聊消息
*
* @author Blue 
* @since 1.0.0 2024-07-19
*/
@RestController
@RequestMapping("im/message/private")
@Tag(name="私聊消息")
@AllArgsConstructor
public class ImPrivateMessageController {
    private final ImPrivateMessageService privateMessageService;


    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('im:message:private:page')")
    public Result<PageResult<ImPrivateMessageVO>> page(@ParameterObject @Valid ImPrivateMessageQueryDTO query){
        PageResult<ImPrivateMessageVO> page = privateMessageService.page(query);
        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('im:message:private:info')")
    public Result<ImPrivateMessageVO> get(@PathVariable("id") Long id){
        ImPrivateMessageVO vo = privateMessageService.info(id);
        return Result.ok(vo);
    }

}